<!--
 * @Author: xuhua
 * @Date: 2023-09-13 16:19:42
 * @LastEditors: xuhua
 * @LastEditTime: 2023-09-19 13:43:57
 * @FilePath: /v3-element-admin/src/views/login/index.vue
 * @Description: 
-->
<template>
	<div>
		<el-form :model="formModel" style="max-width: 460px">
			<el-form-item label="username">
				<el-input v-model="formModel.username" />
			</el-form-item>
			<el-form-item label="password">
				<el-input v-model="formModel.password" />
			</el-form-item>
			<!-- <el-row :gutter="0">
				<el-col :span="16">
					<el-form-item required prop="inputCode">
						<el-input v-model="formModel.inputCode" size="large" type="text" placeholder="请输入验证码">
							<el-icon slot="prefix" type="smile" :style="{ color: 'rgba(0,0,0,.25)' }" />
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8" style="text-align: right">
					<img style="margin-top: 2px" :src="randCodeImage" @click="getRandomImage" />
				</el-col>
			</el-row> -->
			<el-button type="primary" @click="onSubmit" v-throttle>Submit</el-button>
		</el-form>
	</div>
</template>

<script setup lang="ts" name="Login">
import { LoginData } from "@/api/auth/types";
import { useUserStore } from "@/store/modules/user";
import { LocationQuery, LocationQueryValue, useRoute } from "vue-router";

const formModel = reactive<LoginData>({
	username: "admin",
	password: "123456",
});
const userStore = useUserStore();
const router = useRouter();
const route = useRoute();

function onSubmit() {
	userStore.login(formModel).then((res) => {
		ElMessage.success("登录成功");
		const query: LocationQuery = route.query;
		const redirect = (query.redirect as LocationQueryValue) ?? "/";
		console.log("file: index.vue:54 ~ userStore.login ~ redirect:", redirect);
		router.push({ path: redirect, query: {} });
	});
}
</script>
